package drawings;

import games.MalyLotek;

import java.text.DateFormat;
import java.util.Date;
import java.util.Locale;

public class MalyLotekDrawingMachine extends DrawingMachine{
	private Drawing drawing;

	public Drawing getDrawing() {
		return drawing;
	}

	public Drawing draw() {

		Locale locale = new Locale("pl", "PL");
		//Calendar cal = Calendar.getInstance(locale);
		//System.out.println(cal.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.LONG, locale));
		Date date = new Date();
		DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.SHORT, locale);
		String dateStr = formatter.format(date);
		//dateStr = formatter.format(date);
		
		Drawing.setNumberOfDrawings(Drawing.getNumberOfDrawings() + 1);

		int[] tableOfBallsToDrawFrom = new int[MalyLotek.numberOfBallsToDrawFrom];
		int[] tableOfDrawedBalls = new int[MalyLotek.numberOfBallsToDraw];

		for (int i = 0; i < tableOfBallsToDrawFrom.length; i++) {
			tableOfBallsToDrawFrom[i] = i + 1;
		}

		int numberOfBallsToDrawFrom = MalyLotek.numberOfBallsToDrawFrom;
		for (int i = 0; i < MalyLotek.numberOfBallsToDraw; i++) {
			int index = (int) (Math.random() * numberOfBallsToDrawFrom);

			tableOfDrawedBalls[i] = tableOfBallsToDrawFrom[index];
			tableOfBallsToDrawFrom[index] = tableOfBallsToDrawFrom[numberOfBallsToDrawFrom - 1];
			numberOfBallsToDrawFrom--;

		}

		drawing = new MalyLotek(Drawing.getNumberOfDrawings(), dateStr, tableOfDrawedBalls);

		return drawing;
	}
}
